<template>
  <div class="container">
    <div class="content">
      <div class="top">
        <div class="header">
          <img alt="logo" class="logo" :src="logoUrl" />
          <span class="title">{{systemName}}</span>
        </div>
        <div class="desc">RVA ADMIN(requirejs + vue + antdv + antd-vue-pro)</div>
      </div>
      <div class="login">
        <a-form @submit="onSubmit" :auto-form-create="(form) => this.form = form">
          <a-tabs size="large" :tab-bar-style="{textAlign: 'center'}" style="padding: 0 2px;">
            <a-tab-pane tab="账户密码登录" key="1">
              <span>
                <a-alert type="error" :closable="true" v-show="error" :message="error" show-icon style="margin-bottom: 24px;" />
              </span>
              <a-form-item
                field-decorator-id="name"
                :field-decorator-options="{rules: [{ required: true, message: '请输入账户名', whitespace: true}]}"
              >
                <a-input autocomplete="off" size="large" placeholder="admin" >
                  <a-icon slot="prefix" type="user"></a-icon>
                </a-input>
              </a-form-item>
              <a-form-item
                field-decorator-id="password"
                :field-decorator-options="{rules: [{ required: true, message: '请输入密码', whitespace: true}]}"
              >
                <a-input size="large" placeholder="admin" type="password">
                  <a-icon slot="prefix" type="lock"></a-icon>
                </a-input>
              </a-form-item>
            </a-tab-pane>
            <a-tab-pane tab="手机号登录" key="2">
              <a-form-item>
                <a-input :auto-complete="false" size="large" placeholder="mobile number" >
                  <a-icon slot="prefix" type="mobile"></a-icon>
                </a-input>
              </a-form-item>
              <a-form-item>
                <a-row :gutter="8" style="margin: 0 -4px">
                  <a-col :span="16">
                    <a-input size="large" placeholder="captcha">
                    <a-icon slot="prefix" type="mail"></a-icon>
                  </a-input>
                  </a-col>
                  <a-col :span="8" style="padding-left: 4px">
                    <a-button style="width: 100%" class="captcha-button" size="large">获取验证码</a-button>
                  </a-col>
                </a-row>
              </a-form-item>
            </a-tab-pane>
          </a-tabs>
          <div>
             <span @click="() => this.remember = !this.remember"><a-checkbox :checked="remember">自动登录</a-checkbox><span>
             <a style="float: right">忘记密码</a>
          </div>
          <a-form-item>
            <a-button :loading="logging" style="width: 100%; margin-top: 24px" size="large" html-type="submit" type="primary">登录</a-button>
          </a-form-item>
          <div>
            其他登录方式
            <a-icon class="icon" type="alipay-circle"></a-icon>
            <a-icon class="icon" type="taobao-circle"></a-icon>
            <a-icon class="icon" type="weibo-circle"></a-icon>
            <router-link style="float: right" to="/dashboard/workplace" >注册账户</router-link>
          </div>
        </a-form>
      </div>
    </div>
    <global-footer :link-list="linkList" :copyright="copyright" />
  </div>
</template>

<script lang="es6">
  const cmp = new Promise((resolve, reject) => {
    require([
      'alias-parser'
    ], function(aliasParser) {
      resolve({
        name: 'Login',
        components: {
          GlobalFooter : load('@LAYOUT/GlobalFooter')
        },
        data () {
          return {
            logoUrl : aliasParser.parse(this.$store.state.setting.logoPath),
            logging: false,
            remember : true,
            error: ''
          }
        },
        computed: {
          systemName () {
            return this.$store.state.setting.systemName;
          },
          linkList () {
            return this.$store.state.setting.footerLinks;
          },
          copyright () {
            return this.$store.state.setting.copyright;
          }
        },
        mounted () {
          this.jQuery('#loading-mask').remove();
        },
        methods: {
          onSubmit (e) {
            e.preventDefault()
            this.form.validateFields((err, values) => {
              if (!err) {
                this.logging = true;
                this.$axios.post('/login', {
                  name: this.form.getFieldValue('name'),
                  password: this.form.getFieldValue('password')
                }).then((res) => {
                  this.logging = false;
                  const result = res.data;
                  if (result.code >= 0) {
                    const user = result.data.user;
                    this.$router.push('/dashboard/workplace');
                    this.$store.commit('account/setuser', user);
                    this.$message.success(result.message, 3);
                  } else {
                    this.error = result.message;
                  }
                })
              }
            })
          }
        }
      })
    });
  });

  module.exports = cmp;
  //# sourceURL= pages/login/Login.vue
</script>

<style scoped>
  .container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: auto;
    background: #f0f2f5 url('https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg') no-repeat center 110px;
    background-size: 100%;
  }
  .container .content {
    padding: 32px 0;
    flex: 1;
  }
  
  @media (min-width: 768px) {
    .container .content {
    padding: 112px 0 24px;
  }

  }
  .container .content .top {
    text-align: center;
  }
  .container .content .top .header {
    height: 44px;
    line-height: 44px;
  }
  .container .content .top .header a {
    text-decoration: none;
  }
  .container .content .top .header .logo {
    height: 44px;
    vertical-align: top;
    margin-right: 16px;
    border-radius: 22px;
  }
  .container .content .top .header .title {
    font-size: 33px;
    color: rgba(0, 0, 0, 0.85);
    font-family: 'Myriad Pro', 'Helvetica Neue', Arial, Helvetica, sans-serif;
    font-weight: 600;
    position: relative;
    top: 2px;
  }
  .container .content .top .desc {
    font-size: 14px;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 12px;
    margin-bottom: 40px;
  }
  .container .content .login {
    width: 368px;
    margin: 0 auto;
  }
  @media screen and (max-width: 576px) {
    .container .content .login {
    width: 95%;
  }

  }
  @media screen and (max-width: 320px) {
    .container .content .login .captcha-button {
      font-size: 14px;
    }
  }
  .container .content .login .icon {
    font-size: 24px;
    color: rgba(0, 0, 0, 0.2);
    margin-left: 16px;
    vertical-align: middle;
    cursor: pointer;
    transition: color 0.3s;
  }
  .container .content .login .icon:hover {
    color: #1890ff;
  }
</style>
